﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace gChartSharp.ChartParams
{
    /// <summary>
    /// http://code.google.com/apis/chart/#axis_range
    /// </summary>
    public class ChartAxisRange : IChartParam
    {
        public string Name { get { return "chxr"; } }

        public Dictionary<int, int[]> LabelRanges { get; set; }

        public string Render()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(String.Format("&{0}=", this.Name));

            foreach (KeyValuePair<int, int[]> kv in this.LabelRanges)
            {
                // only render the KeyValuePair if there is at least one label range in the array
                if (kv.Value.Count() > 0)
                {
                    sb.Append(String.Format("{0},", kv.Key));

                    foreach (int labelRange in kv.Value)
                        sb.Append(String.Format("{0}", labelRange));

                    sb.Append(String.Format("{0}", "|"));
                }
            }

            sb.Remove(sb.ToString().LastIndexOf('|'), 1);

            return sb.ToString();
        }
    }
}
